
package fr.mehfile.view.utils;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

public class Utils {

    static boolean DEBUGMODE = true;

    public static final Debugable debugger = CreateDebugger();

    private static Debugable CreateDebugger() {
        Debugable debugger = null;

        if (DEBUGMODE)
            debugger = new Debug();

        return debugger;
    }
    
    public static boolean isDebugMode() {
        return DEBUGMODE;
    }
    
    public static int getVersionCode(Context context){

        PackageManager packageManager = context.getPackageManager();
        PackageInfo packageInfo = null;
        try {
            packageInfo = packageManager.getPackageInfo(context.getPackageName(),0);
            return packageInfo.versionCode;
        }catch (Exception e) {}
        
        return -1;
    }
    


	public static String getVersionName(Context context) {

		PackageManager packageManager = context.getPackageManager();
		PackageInfo packageInfo = null;
		try {
			packageInfo = packageManager.getPackageInfo(
					context.getPackageName(), 0);
			return packageInfo.versionName;
		} catch (Exception e) {
		}

		return null;
	}
	
	public static String getEmail(Context context) {
	    AccountManager accountManager = AccountManager.get(context); 
	    Account account = getAccount(accountManager);

	    if (account == null) {
	      return null;
	    } else {
	      return account.name;
	    }
	  }

	public static Account getAccount(AccountManager accountManager) {
	    Account[] accounts = accountManager.getAccountsByType("com.google");
	    Account account;
	    if (accounts.length > 0) {
	      account = accounts[0];      
	    } else {
	      account = null;
	    }
	    return account;
	  }

}
